package com.example.bookstore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.bookstore.common.Result;
import com.example.bookstore.entity.Addressee;
import com.example.bookstore.mapper.AddresseeMapper;
import com.example.bookstore.service.AddresseeService;
import com.sun.xml.internal.ws.wsdl.writer.document.http.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddresseeServiceImpl extends ServiceImpl<AddresseeMapper, Addressee> implements AddresseeService {
    @Autowired
    private AddresseeMapper addresseeMapper;
    @Override
    public Result getAddress(Integer userId) {
        LambdaQueryWrapper<Addressee> qw=new LambdaQueryWrapper<>();
        qw.eq(Addressee::getUserId,userId);
        List<Addressee> addressees = addresseeMapper.selectList(qw);
        return Result.success(addressees);
    }
    @Override
    public Result<String> deleteAddress(Integer id) {
        addresseeMapper.deleteById(id);
        return Result.success("删除成功");
    }

    @Override
    public Result<String> addAddress(Addressee address) {
        addresseeMapper.insert(address);
        return Result.success("添加成功");
    }

    @Override
    public Result<String> updateAddress(Addressee address) {
        addresseeMapper.updateById(address);
        return Result.success("修改成功");
    }


}
